Page({
    data: {
        more_list: !1,
        _num: 8,
        list: [],
        today: "",
        yesterday: "",
        page_loading: !0,
        num: {}
    },
    tab: function(t) {
        var a = this, e = t.currentTarget.dataset.num;
        this.setData({
            _num: e,
            list: []
        }), 1 == e ? a.getPut() : a.getList();
    },
    onLoad: function(t) {
        var a = new Date(), e = a.getFullYear(), i = a.getMonth() + 1;
        i >= 1 && i <= 9 && (i = "0" + i);
        var n = e + "-" + i + "-" + a.getDate(), s = 1e3 * (Date.parse(new Date()) / 1e3 - 86400), r = new Date(s), d = r.getFullYear(), o = r.getMonth() + 1;
        o >= 1 && o <= 9 && (o = "0" + o);
        var g = d + "-" + o + "-" + r.getDate();
        this.setData({
            today: n,
            yesterday: g
        }), this.getList();
    },
    getList: function() {
        var t = this;
        getApp().iView.$Toast({
            content: "加载中",
            type: "loading",
            duration: 0
        }), getApp().request({
            url: getApp().apiUrl.app_admin.order,
            data: {
                status: t.data._num
            },
            method: "post"
        }).then(function(a) {
            if (getApp().iView.$Toast.hide(), 0 == a.data.code) {
                var e = a.data.data.list;
                e.forEach(function(a, e) {
                    a.created_at.substring(0, 10) == t.data.today ? a.created_at = a.created_at.substring(11) : a.created_at.substring(0, 10) == t.data.yesterday ? a.created_at = "昨天" : a.created_at = a.created_at.substring(0, 10);
                });
                var i = !1;
                20 == e.length && (i = !0), t.setData({
                    list: e,
                    more_list: i,
                    page: 2
                });
            } else getApp().iView.$Toast({
                content: a.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    getMore: function() {
        var t = this, a = this.data.page, e = this;
        getApp().iView.$Toast({
            content: "加载中",
            type: "loading",
            duration: 0
        }), getApp().request({
            url: getApp().apiUrl.app_admin.order,
            data: {
                page: a,
                status: e.data._num
            },
            method: "get"
        }).then(function(i) {
            if (getApp().iView.$Toast.hide(), 0 == i.data.code) {
                var n = t.data.list, s = i.data.data.list, r = !1;
                20 == s.length && (r = !0), s.forEach(function(t, a) {
                    t.created_at.substring(0, 10) == e.data.today ? t.created_at = t.created_at.substring(11) : t.created_at.substring(0, 10) == e.data.yesterday ? t.created_at = "昨天" : t.created_at = t.created_at.substring(0, 10);
                }), n = n.concat(s), a++, e.setData({
                    list: n,
                    moreList: s,
                    more_list: r,
                    page: a
                });
            } else getApp().iView.$Toast({
                content: i.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    getPut: function() {
        var t = this;
        getApp().iView.$Toast({
            content: "加载中",
            type: "loading",
            duration: 0
        }), getApp().request({
            url: getApp().apiUrl.app_admin.refund,
            data: {
                status: 0
            },
            method: "post"
        }).then(function(a) {
            if (getApp().iView.$Toast.hide(), 0 == a.data.code) {
                var e = a.data.data.list;
                e.forEach(function(a, e) {
                    a.detail = [ a.detail ], a.created_at.substring(0, 10) == t.data.today ? a.created_at = a.created_at.substring(11) : a.created_at.substring(0, 10) == t.data.yesterday ? a.created_at = "昨天" : a.created_at = a.created_at.substring(0, 10);
                }), t.setData({
                    list: e
                });
            } else getApp().iView.$Toast({
                content: a.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    getPutMore: function(t) {
        var a = this, e = this;
        getApp().iView.$Toast({
            content: "加载中",
            type: "loading",
            duration: 0
        }), getApp().request({
            url: getApp().apiUrl.app_admin.refund,
            data: {
                status: 0,
                page: t
            },
            method: "get"
        }).then(function(i) {
            if (getApp().iView.$Toast.hide(), 0 == i.data.code) {
                var n = a.data.list, s = i.data.data.list, r = !1;
                20 == s.length && (r = !0), n.forEach(function(t, a) {
                    t.detail = [ t.detail ], t.created_at.substring(0, 10) == e.data.today ? t.created_at = t.created_at.substring(11) : t.created_at.substring(0, 10) == e.data.yesterday ? t.created_at = "昨天" : t.created_at = t.created_at.substring(0, 10);
                }), n = n.concat(s), t++, e.setData({
                    list: n,
                    moreList: s,
                    more_list: r,
                    page: t
                });
            } else getApp().iView.$Toast({
                content: i.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    onReady: function(t) {
        this.setData({
            page_loading: !1
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.more_list && (1 == this.data._num ? this.getPutMore(this.data.page) : this.getMore(this.data.page));
    },
    onShareAppMessage: function() {}
});